package com.xw.controller.admin;


import com.xw.entity.Admin;
import com.xw.service.IAdminService;
import com.xw.vo.ResultVO;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author y
 * @since 2021-09-14
 */
@RestController
@RequestMapping("/admin")
public class AdminController {
    private final IAdminService iAdminService;

    public AdminController(IAdminService iAdminService) {
        this.iAdminService = iAdminService;
    }

    /**
     * 管理员登陆
     *
     * @return
     */
    @PostMapping({"/toLogin"})
    public ResultVO<?> toLogin(@RequestBody Admin admin) {
        return iAdminService.toLogin(admin.getUsername(), admin.getPwd());
    }

    /**
     * 管理员退出
     */
    @PostMapping({"/logout"})
    public ResultVO<?> logout(@RequestParam("userId") String userId) {
        return iAdminService.logout(userId);
    }

    /**
     * 管理员修改密码
     */
    @PostMapping({"/updPwd"})
    public ResultVO<?> updPwd(@RequestParam("userId") String userId, @RequestParam("oldPwd") String oldPwd, @RequestParam("newPwd") String newPwd) {
        return iAdminService.updPwd(userId, oldPwd, newPwd);
    }


}

